package general;

/**
 *
 * @author Kylan Robinson (krobinso@eecs.wsu.edu)
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        int failures;
        
        System.out.println(" ==========================");         
        System.out.println("||  HiPerCopS Washington  ||");
        System.out.println(" ==========================\n");
        
        Device dev;
        dev = new Device(128, 4);
        dev.printTypes();
        
//        TC_Mult tcm;
//        tcm = new TC_Mult(16, 4);
//        tcm.printTypes();
//        tcm.printTypes_Rotate();
//        
//        Memory mem;
//        mem = new Memory(16, 4);
//        mem.printTypes();
//        
//        Add add;
//        add = new Add(8, 4, 2);
//        add.printTypes();
//        add.printTypes_Rotate();
//        
//        Sub sub;
//        sub = new Sub(8, 4, 2);
//        sub.printTypes();
        
        //create an FFT to place on the device
/*        
        ////define 12 multipliers
        TC_Mult tcm00, tcm01, tcm02, tcm03, tcm04, tcm05;
        TC_Mult tcm06, tcm07, tcm08, tcm09, tcm10, tcm11;
        
        tcm00 = new TC_Mult(16, 4);
        tcm01 = new TC_Mult(16, 4);
        tcm02 = new TC_Mult(16, 4);
        tcm03 = new TC_Mult(16, 4);
        tcm04 = new TC_Mult(16, 4);
        tcm05 = new TC_Mult(16, 4);
        tcm06 = new TC_Mult(16, 4);
        tcm07 = new TC_Mult(16, 4);
        tcm08 = new TC_Mult(16, 4);
        tcm09 = new TC_Mult(16, 4);
        tcm10 = new TC_Mult(16, 4);
        tcm11 = new TC_Mult(16, 4);
        
        ////define 11 adders
        Add add00, add01, add02, add03, add04, add05;
        Add add06, add07, add08, add09, add10;
        
        add00 = new Add(8, 4, 2);
        add01 = new Add(8, 4, 2);
        add02 = new Add(8, 4, 2);
        add03 = new Add(8, 4, 2);
        add04 = new Add(8, 4, 2);
        add05 = new Add(8, 4, 2);
        add06 = new Add(8, 4, 2);
        add07 = new Add(8, 4, 2);
        add08 = new Add(8, 4, 2);
        add09 = new Add(8, 4, 2);
        add10 = new Add(8, 4, 2);        
        
        ////define 11 subtractors
        Sub sub00, sub01, sub02, sub03, sub04, sub05;
        Sub sub06, sub07, sub08, sub09, sub10;
        
        sub00 = new Sub(8, 4, 2);
        sub01 = new Sub(8, 4, 2);
        sub02 = new Sub(8, 4, 2);
        sub03 = new Sub(8, 4, 2);
        sub04 = new Sub(8, 4, 2);
        sub05 = new Sub(8, 4, 2);
        sub06 = new Sub(8, 4, 2);
        sub07 = new Sub(8, 4, 2);
        sub08 = new Sub(8, 4, 2);
        sub09 = new Sub(8, 4, 2);
        sub10 = new Sub(8, 4, 2);
        
        ////define 8 memories
        
        Memory mem00, mem01, mem02, mem03;
        Memory mem04, mem05, mem06, mem07;
        
        mem00 = new Memory(16, 4);
        mem01 = new Memory(16, 4);
        mem02 = new Memory(16, 4);
        mem03 = new Memory(16, 4);
        mem04 = new Memory(16, 4);
        mem05 = new Memory(16, 4);
        mem06 = new Memory(16, 4);
        mem07 = new Memory(16, 4);
        
        //place the modules on the device
        
        dev.addModule(add00);
        dev.addModule(add01);
        dev.addModule(add02);
        dev.addModule(add03);
        dev.addModule(add04);
        dev.addModule(add05);
        dev.addModule(add06);
        dev.addModule(add07);
        dev.addModule(add08);
        dev.addModule(add09);
        dev.addModule(add10);
        
        dev.addModule(tcm00);
        dev.addModule(tcm01);
        dev.addModule(tcm02);
        dev.addModule(tcm03);
        dev.addModule(tcm04);
        dev.addModule(tcm05);
        dev.addModule(tcm06);
        dev.addModule(tcm07);
        dev.addModule(tcm08);
        dev.addModule(tcm09);
        dev.addModule(tcm10);
        dev.addModule(tcm11);
        
        dev.addModule(mem00);
        dev.addModule(mem01);
        dev.addModule(mem02);
        dev.addModule(mem03);
        dev.addModule(mem04);
        dev.addModule(mem05);
        dev.addModule(mem06);
        dev.addModule(mem07);
        
        dev.addModule(sub00);
        dev.addModule(sub01);
        dev.addModule(sub02);
        dev.addModule(sub03);
        dev.addModule(sub04);
        dev.addModule(sub05);
        dev.addModule(sub06);
        dev.addModule(sub07);
        dev.addModule(sub08);
        dev.addModule(sub09);
        dev.addModule(sub10);
        
//        
//        System.out.println("---------------------");
//        System.out.println("  Initial Placement");
//        System.out.println("---------------------");
//        System.out.println("map: " + dev.placeModules(4));
//        dev.printTypes();
//        
//        System.out.println("---------------------");        
//        System.out.println("   Fault Injection");
//        System.out.println("---------------------");
//        dev.injectFaults(30);
//        dev.printTypes();
//        
//        System.out.println("---------------------");
//        System.out.println("      Remapping");
//        System.out.println("---------------------");
//        dev.format();
//        System.out.println("remap: " + dev.placeModules(4));
//        dev.printTypes();
        
        
        
        //for each of the different placement algorithms
        for(int placer = 1; placer <= 4; placer++) {
            System.out.println("placer: " + placer);
            //vary the number of faults from 0 to 220
            for(int num_faults = 0; num_faults < 220; num_faults++) {
                failures = 0;
                //100 trials per placment algorithm / number of faults pair
                for(int trial = 0; trial < 5000; trial++) {
                    dev.replace(); //start with a new device
                    dev.injectFaults(num_faults); //inject the faults
                    if(dev.placeModules(placer) == false) {
                        failures++;
                    }
                }
                System.out.println(failures);
            }
        }
        
//        TC_Mult tcm;
//        tcm = new TC_Mult(16, 4);
//        tcm.multiply(12, 12);
//        tcm.printTypes();
//        tcm.printValues();
        
//        US_Mult usm;
//        usm = new US_Mult(16, 4);
//        usm.multiply(256, 256);
//        usm.printTypes();
//        usm.printValues();
        
//        US_Mult usm2;
//        usm2 = new US_Mult(16, 4);
//        usm2.printTypes();

        System.out.println("\n ---------------------------");        
        System.out.println("| Multiply Positive Numbers |");
        System.out.println(" ---------------------------\n");
        
        System.out.println("multiply 0 and 0");
        result = multiplier.multiply(0, 0);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 0");
        multiplier.printValues();
        
        System.out.println("\nmultiply 1 and 0");
        result = multiplier.multiply(1, 0);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 0");
        multiplier.printValues();

        System.out.println("\nmultiply 0 and 1048575");
        result = multiplier.multiply(0, 1048575);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 0");
        multiplier.printValues();
        
        System.out.println("\nmultiply 1 and 1");
        result = multiplier.multiply(1, 1);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 1");
        multiplier.printValues();
        
        System.out.println("\nmultiply 2 and 2");
        result = multiplier.multiply(2, 2);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 4");
        multiplier.printValues();
        
        System.out.println("\nmultiply 4 and 4");
        result = multiplier.multiply(4, 4);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 16");
        multiplier.printValues();
        
        System.out.println("\nmultiply 32 and 32");
        result = multiplier.multiply(32, 32);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 1024");
        multiplier.printValues();
        
        System.out.println("\nmultiply 128 and 128");
        result = multiplier.multiply(128, 128);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 16384");
        multiplier.printValues();
        
        System.out.println("\nmultiply 512 and 512");
        result = multiplier.multiply(512, 512);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 262144");
        multiplier.printValues();
        
        System.out.println("\nmultiply 2048 and 2048");
        result = multiplier.multiply(2048, 2048);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 4194304");
        multiplier.printValues();

        System.out.println("\nmultiply 8192 and 8192");
        result = multiplier.multiply(8192, 8192);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 67108864");
        multiplier.printValues();
        
        System.out.println("\nmultiply 32768 and 32768");
        result = multiplier.multiply(32768, 32768);
        System.out.println(" (" + result + ")");
        System.out.println("expect::  1073741824");
        multiplier.printValues();
        
        System.out.println("\nmultiply 131072 and 131072");
        result = multiplier.multiply(131072, 131072);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 17179869184");
        multiplier.printValues();
        
        System.out.println("\nmultiply 524287 and 524287");
        result = multiplier.multiply(524287, 524287);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 274876858369");
        multiplier.printValues();
        
        System.out.println("\n ---------------------------");
        System.out.println("| Multiply Negative Numbers |");
        System.out.println(" ---------------------------\n");
 
        System.out.println("multiply -1 and 1");
        result = multiplier.multiply(-1, 1);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: -1");
        multiplier.printValues();
        
        System.out.println("\nmultiply -4 and 1");
        result = multiplier.multiply(-4, 1);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: -4");
        multiplier.printValues();        
        
        System.out.println("\nmultiply 1 and -1");
        result = multiplier.multiply(1, -1);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: -1");
        multiplier.printValues();
        
        System.out.println("\nmultiply 4 and -1");
        result = multiplier.multiply(4, -1);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: -4");
        multiplier.printValues();
        
        System.out.println("\nmultiply -1 and -1");
        result = multiplier.multiply(-1, -1);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 1");
        multiplier.printValues();
        
        System.out.println("\nmultiply -4 and -1");
        result = multiplier.multiply(-4, -1);
        System.out.println(" (" + result + ")");
        System.out.println("expect:: 4");
        multiplier.printValues();        
        */
    }
}
